/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.documents.service.document;

import com.documents.common.core.PageBean;
import com.documents.common.core.service.BaseSrv;

import com.documents.pojo.FillPoints;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class FillPointsService extends BaseSrv<FillPoints, Integer> {

         public PageBean getPageBean(int page, int pageSize, FillPoints points) {
        PageBean pageBean = new PageBean();
        pageBean.setPageSize(pageSize);
        pageBean.setCurrentPage(page);
        String condition = "";
        Object[] parameters = new Object[1];
        int paramIndex = 0;
        if (points != null) {
            int pid = points.getDocument_id();
            if (pid >= 0) {
                condition = condition + "document_id=?";
                parameters[paramIndex] = new Integer(pid);
                paramIndex++;
            }
            Long allRow = this.findTotalCount(condition, parameters);
            int totalPage = PageBean.countTotalPage(pageSize, allRow.intValue()); // 总页数
            pageBean.setAllRow(allRow.intValue());
            pageBean.setTotalPage(totalPage);
            List<FillPoints> list;
            if (page == 1) {
                list = this.findWithPaging(condition, parameters, "id", page-1, pageSize);
            } else {
                list = this.findWithPaging(condition, parameters, "id", (page - 1) * pageSize, pageSize);
            }

            pageBean.setList(list);

        } else {
            Long allRow = this.findTotalCount("", null);
            int totalPage = PageBean.countTotalPage(pageSize, allRow.intValue()); // 总页数
            pageBean.setAllRow(allRow.intValue());
            pageBean.setTotalPage(totalPage);
             List<FillPoints> list;
            if (page == 1) {
                list = this.findWithPaging(condition, parameters, "id", page-1, pageSize);
            } else {
                list = this.findWithPaging(condition, parameters, "id", (page - 1) * pageSize, pageSize);
            }

            pageBean.setList(list);
        }
        return pageBean;
    }
         
          
     public PageBean getPageBeanByDocId(int page, int pageSize, int docId) {
        PageBean pageBean = new PageBean();
        pageBean.setPageSize(pageSize);
        pageBean.setCurrentPage(page);
        String condition = "";
        Object[] parameters = new Object[1];
        int paramIndex = 0;
        if (docId > 0) {
       
                condition = condition + "document_id=?";
                parameters[paramIndex] = new Integer(docId);
                paramIndex++;
            
            Long allRow = this.findTotalCount(condition, parameters);
            int totalPage = PageBean.countTotalPage(pageSize, allRow.intValue()); // 总页数
            pageBean.setAllRow(allRow.intValue());
            pageBean.setTotalPage(totalPage);
            List<FillPoints> list;
            if (page == 1) {
                list = this.findWithPaging(condition, parameters, "id", page-1, pageSize);
            } else {
                list = this.findWithPaging(condition, parameters, "id", (page - 1) * pageSize, pageSize);
            }

            pageBean.setList(list);

        } else {
            Long allRow = this.findTotalCount("", null);
            int totalPage = PageBean.countTotalPage(pageSize, allRow.intValue()); // 总页数
            pageBean.setAllRow(allRow.intValue());
            pageBean.setTotalPage(totalPage);
             List<FillPoints> list;
            if (page == 1) {
                list = this.findWithPaging(condition, parameters, "id", page-1, pageSize);
            } else {
                list = this.findWithPaging(condition, parameters, "id", (page - 1) * pageSize, pageSize);
            }

            pageBean.setList(list);
        }
        return pageBean;
    }
}
